class UnexpectedErr{
  /**
   * 函数入参判空
   * @param {String} fnName        标识错误位置
   * @param {String} para          为空的参数描述
  */
  static fnArgumentsEmptyErr(fnName, para) {
    fnName = !fnName ? '' : fnName
    para = !para ? 'xiaojiji' : para
    throw new Error(`${fnName} without parameter ${para}. Please confirm parameter is not empty.`)
  }

  /**
   * 错误提示
   * @param {boolean} codition     抛出错误的判断条件 
   * @param {String} tip                自定义的错误提示
  */
  static errTip(codition, tip='Uncatch error occurred') {
    if(codition) throw new Error(tip)
  }

  /**
   * 指定类型判空
   * @param {dynamic} arg 
   * @param {String} type 
  */
  static fixedTypeEmptyErr(arg, type='string') {
    // 需要处理为0的情况
    if(arg === 0) {
      UnexpectedErr.errTip(typeof arg != type, `need a ${type}, but get a number`)
    }else{
      UnexpectedErr.errTip(!arg, `argument is ${arg}, Please confirm parameter is not empty`)
    }
    
    UnexpectedErr.errTip(typeof arg != type, `need a ${type}, but get a ${typeof arg}`)
    return arg 
  }
}

export default UnexpectedErr